import React, { Component } from 'react'
import "./index.css"

export default class Footer extends Component {
    handleCheckAll = (event) => {
        this.props.checkAll(event.target.checked)
    }
    removeIsDone = () => {
        this.props.removeIsDone()
    }
    render() {
        const {todos} = this.props;
        // 计算已完成数量
        let isDone = todos.reduce((pre,current) => {return pre + (current.done ? 1 : 0)},0)
        let total = todos.length;
        return (
            <div className="todo-footer">
                <label>
                    <input type="checkbox" onChange={this.handleCheckAll} checked={isDone === total && total !== 0 ? true : false} />
                </label>
                <span>
                    <span>已完成{isDone}</span> / 全部{total}
                </span>
                <button style={{ display: isDone ? 'block' : "none" }} className="btn btn-danger" onClick={this.removeIsDone}>清除已完成任务</button>
            </div>

        )
    }
}
